package com.dong.cutesms.components;

import java.util.List;

import com.dong.cutesms.R;
import com.dong.cutesms.constant.AppParameters;
import com.dong.cutesms.constant.SmsTable;
import com.dong.cutesms.models.SmsModel;


import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnDragListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HorizontalImageAdapter extends BaseAdapter {

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}

	private Activity context;


	private List plotsImages;
	private List<SmsModel> smsList;
	private static ViewHolder holder;
	private LayoutInflater l_Inflater;

	public HorizontalImageAdapter(Activity context, List plotsImages, List<SmsModel> _smsList ) {
		this.context = context;
		this.plotsImages = plotsImages;
		this.smsList = _smsList;
		l_Inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		//System.out.println("count="+ String.valueOf(AppParameters.smsList.size()));
		if(AppParameters.smsList == null){
			return 0;
		}
		return AppParameters.smsList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return AppParameters.smsList.get(position).id;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = l_Inflater.inflate(R.layout.item_activity_horizontal_chat_region, null);
			holder = new ViewHolder();
			holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
			holder.tv = (TextView) convertView.findViewById(R.id.tv_text_chat);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();
		}
		
		final int temp = position;
		
		SmsModel sms = AppParameters.smsList.get(position);
		
		System.out.print("position:");
		System.out.println(position);
		
		
		int smsType = sms.type;
		if(smsType == SmsTable.MESSAGE_TYPE_INBOX){
			holder.imageView.setImageResource(AppParameters.people.avatarID);
			holder.tv.setBackgroundResource(R.drawable.chat_bubble2);
		}
		else{
			holder.imageView.setImageResource(AppParameters.user.avatarID);
			holder.tv.setBackgroundResource(R.drawable.chat_bubble);
		}
		String message = sms.body;
		holder.tv.setText(message);
		
		return convertView;
	}

	private static class ViewHolder {
		ImageView imageView;
		TextView tv;
	}

}
